<?php
namespace Api\Controller;
/**
 * 分享
 */
class ShareController extends ApiController
{
    protected $noCheck = [];

    function _initialize() {
        parent::_initialize();
    }

    /**
     * 分享记录
     */
    public function log()
    {
        $scene = I('scene');
        $relation_id = I('relation_id', 0);
        $model = M('share_log');
        $data = [
            'scene'         => $scene,
            'relation_id'   => $relation_id,
            'user_id'       => $this->uid ? $this->uid : 0,
            'create_time'   => time(),
        ];
        switch ($scene) {
            // case 'qd':
            //     // 签到
            //     break;
            // case 'member_no':
            //     // 会员号
            //     break;
            case 'mahjong':
                // 麻将机
                M('share_mahjong')->where(['id'=>$relation_id])->setInc('share_num', 1);
                break;
        }
        $insert_id = $model->add($data);
        if($insert_id){
            $member_no = M('member_no')->where(['user_id'=>$this->uid])->find();
            if($member_no){
                member_no_like($member_no['member_no'], 2, $insert_id);
            }
            $this->ajaxReturn(['s'=>true, 'm'=>'ok']);
        }else{
            $this->ajaxReturn(['s'=>false, 'm'=>'记录失败']);
        }
    }
}